home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mymem1 / mymemory.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  17.1 KB  |  484 lines

  1. VERSION 2.00
  2. Begin Form MyMemory 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Your Memory Is What?"
  6.    ClientHeight    =   1575
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1740
  9.    ClientWidth     =   4155
  10.    Height          =   2265
  11.    Icon            =   MYMEMORY.FRX:0000
  12.    Left            =   1035
  13.    LinkMode        =   1  'Source
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    ScaleHeight     =   105
  17.    ScaleMode       =   3  'Pixel
  18.    ScaleWidth      =   277
  19.    Tag             =   "MyMemory"
  20.    Top             =   1110
  21.    Width           =   4275
  22.    Begin Label LabelSquareStatus 
  23.       Alignment       =   2  'Center
  24.       BackColor       =   &H0000FFFF&
  25.       FontBold        =   -1  'True
  26.       FontItalic      =   0   'False
  27.       FontName        =   "MS Sans Serif"
  28.       FontSize        =   12
  29.       FontStrikethru  =   0   'False
  30.       FontUnderline   =   0   'False
  31.       ForeColor       =   &H000000FF&
  32.       Height          =   375
  33.       Left            =   120
  34.       TabIndex        =   0
  35.       Top             =   1080
  36.       Width           =   3615
  37.    End
  38.    Begin Label LabelFieldStatus 
  39.       Alignment       =   2  'Center
  40.       BackColor       =   &H00FFFF00&
  41.       FontBold        =   -1  'True
  42.       FontItalic      =   0   'False
  43.       FontName        =   "MS Sans Serif"
  44.       FontSize        =   12
  45.       FontStrikethru  =   0   'False
  46.       FontUnderline   =   0   'False
  47.       Height          =   375
  48.       Left            =   120
  49.       TabIndex        =   1
  50.       Top             =   600
  51.       Width           =   3615
  52.    End
  53.    Begin Label FieldDesc 
  54.       Alignment       =   2  'Center
  55.       FontBold        =   -1  'True
  56.       FontItalic      =   0   'False
  57.       FontName        =   "MS Sans Serif"
  58.       FontSize        =   12
  59.       FontStrikethru  =   0   'False
  60.       FontUnderline   =   0   'False
  61.       Height          =   375
  62.       Left            =   120
  63.       TabIndex        =   2
  64.       Top             =   120
  65.       Width           =   3615
  66.    End
  67.    Begin Menu MenuGame 
  68.       Caption         =   "&Game"
  69.       Begin Menu MenuNew 
  70.          Caption         =   "&New Game"
  71.          Shortcut        =   {F2}
  72.       End
  73.       Begin Menu MenuSettings 
  74.          Caption         =   "&Settings"
  75.          Shortcut        =   {F3}
  76.       End
  77.       Begin Menu MenuShowRecord 
  78.          Caption         =   "Show &Record"
  79.          Shortcut        =   {F4}
  80.       End
  81.       Begin Menu MenuSepBar 
  82.          Caption         =   "-"
  83.       End
  84.       Begin Menu MenuExit 
  85.          Caption         =   "E&xit"
  86.          Shortcut        =   ^X
  87.       End
  88.    End
  89.    Begin Menu MenuHelp 
  90.       Caption         =   "&Help"
  91.    End
  92. 'From example in VB Language Reference manual page 141
  93. Declare Sub FloodFill Lib "GDI" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal Color As Long)
  94. 'Needed to get physical size of screen (from WINAPI.TXT)
  95. Const HORZRES = 8
  96. Const VERTRES = 10
  97. Declare Function GetDeviceCaps Lib "GDI" (ByVal hDC As Integer, ByVal nIndex As Integer) As Integer
  98. Sub Form_Load ()
  99.     NL = Chr$(13) + Chr$(10)
  100. 'initialize user settings, in case no profile
  101.     NumberXSquares = DefaultXSquares
  102.     NumberYSquares = DefaultYSquares
  103.     SquareSize = DefaultSquareSize
  104.     SetTimer = DefaultTimer
  105.     SaveFile = SelectSaveFileNo
  106.     SaveScore = UNCHECKED
  107.     For I% = 0 To 5
  108.         For J% = 0 To 2
  109.             ScoreArray(I%, J%) = NoScore
  110.         Next J%
  111.     Next I%
  112.     ScreenPixelSizeX = GetDeviceCaps(hDC, HORZRES)
  113.     ScreenPixelSizeY = GetDeviceCaps(hDC, VERTRES)
  114. 'Indicate no change to Game Setup since beginning or after reading profile
  115.     SaveFileChange = False
  116. 'See if there is a game setup (profile) in an INI file
  117.     MyProfile
  118. 'Change array size to match number of squares, especially if MyProfile changed size
  119.     ReDim SquareStatusArray(NumberXSquares, NumberYSquares)
  120.     ReDim SquareSceneArray(NumberXSquares, NumberYSquares)
  121. 'indicate game not started
  122.     FieldStatus = FieldNotReady
  123. 'set form size - Form set smaller during development because
  124. 'it was easier to work with
  125.     Top = 0
  126.     Left = 0
  127.     ResizeMyMemoryForm
  128.     Show
  129. End Sub
  130. Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  131. 'Get X and Y offsets for scene and status variable arrays
  132.     Xs% = X \ SquareSize
  133.     Ys% = Y \ SquareSize
  134. 'Get X and Y pixel offsets for square
  135.     Xp% = Xs% * SquareSize
  136.     Yp% = Ys% * SquareSize
  137. 'Process left button click, ignore right or middle button
  138.     If Button = LEFT_BUTTON Then
  139.         
  140.         'is game in progress
  141.         If FieldStatus = FieldReady Then
  142.             
  143.             'process square only if closed, ignore if open with scene
  144.             If SquareStatusArray(Xs%, Ys%) = FieldClosed Then
  145.                 Scene% = SquareSceneArray(Xs%, Ys%)
  146.                 
  147.                 'open square and show scene, but don't allow a third to show
  148.                 'before processing first two (if you click ahead 3 times)
  149.                 If CurrentSquare < 2 Then ShowSquare Xp%, Yp%, Scene%
  150.                 
  151.                 If CurrentSquare = 0 Then
  152.                     'get first square of pair
  153.                     CurrentSquare = 1
  154.                     CurrentSquare1 = Scene%
  155.                     CurrentSquare1X = Xs%
  156.                     CurrentSquare1Y = Ys%
  157.                     SquareStatusArray(Xs%, Ys%) = SquareOpen
  158.                 
  159.                 ElseIf CurrentSquare = 1 Then
  160.                     CurrentSquare = 2
  161.                     
  162.                     'get second square of pair and see if they match
  163.                     If CurrentSquare1 <> Scene% Then
  164.                         LabelSquareStatus.Caption = "Squares do not Match!"
  165.                         'give VB time to display caption
  166.                         Temp% = DoEvents()
  167.                         MyTimer SetTimer
  168.                         BuildSquare Xp%, Yp%
  169.                         Xp% = CurrentSquare1X * SquareSize
  170.                         Yp% = CurrentSquare1Y * SquareSize
  171.                         BuildSquare Xp%, Yp%
  172.                         SquareStatusArray(CurrentSquare1X, CurrentSquare1Y) = SquareClosed
  173.                         LabelSquareStatus.Caption = ""
  174.                     Else
  175.                         LabelSquareStatus.Caption = "Squares Match!"
  176.                         SquareStatusArray(Xs%, Ys%) = SquareSolved
  177.                         SquareStatusArray(CurrentSquare1X, CurrentSquare1Y) = SquareSolved
  178.                         CurrentSolved = CurrentSolved + 2
  179.                     End If
  180.                     
  181.                     'after showing second square, reset and update
  182.                     CurrentSquare = 0
  183.                     CurrentMoves = CurrentMoves + 1
  184.                     
  185.                     LabelFieldStatus.Caption = "You have made" + Str$(CurrentMoves) + MoveWord
  186.                     If CurrentMoves = 1 Then MoveWord = " moves."
  187.                     
  188.                     'see if user solved available number of pairs
  189.                     If CurrentSolved = NumberXSquares * NumberYSquares Then
  190.                         SaveMyScore
  191.                         FieldStatus = FieldSolved
  192.                         LabelSquareStatus.Caption = "Game Solved"
  193.                     End If
  194.                 End If
  195.             End If
  196.         Else
  197.             'Field not ready or solved, go build field
  198.             InitField
  199.         End If
  200.     End If
  201. End Sub
  202. Sub Form_Paint ()
  203. 'Build existing game, SquareOpen should not be a problem
  204. 'because its status will soon change
  205.     If FieldStatus <> FieldNotReady Then
  206.         For X% = 0 To (NumberXSquares - 1)
  207.             For Y% = 0 To (NumberYSquares - 1)
  208.                 Xp% = X% * SquareSize
  209.                 Yp% = Y% * SquareSize
  210.                 If SquareStatusArray(X%, Y%) = SquareClosed Then
  211.                     BuildSquare Xp%, Yp%
  212.                 ElseIf SquareStatusArray(X%, Y%) = SquareSolved Then
  213.                     Scene% = SquareSceneArray(X%, Y%)
  214.                     ShowSquare Xp%, Yp%, Scene%
  215.                 End If
  216.             Next Y%
  217.         Next X%
  218.     End If
  219. End Sub
  220. Sub Form_Unload (Cancel As Integer)
  221.     SaveMyProfile
  222.     End
  223. End Sub
  224. Sub MenuExit_Click ()
  225.     Msg$ = "Do you really want to quit?"
  226.     Response% = MsgBox(Msg$, MB_YESNO, "Quit")
  227.     If Response% = IDYES Then
  228.         SaveMyProfile
  229.         End
  230.     End If
  231. End Sub
  232. Sub MenuHelp_Click ()
  233.     MyHelp.Show 1
  234. End Sub
  235. Sub MenuNew_Click ()
  236. 'If game started, see if user really wants to quit
  237.     If FieldStatus = FieldReady Then
  238.         Msg$ = "You haven't finished playing the current game!" + NL
  239.         Msg$ = Msg$ + "Do you really want to start a new game?"
  240.         Response% = MsgBox(Msg$, MB_YESNO, "New Game")
  241.         If Response% <> IDYES Then Exit Sub
  242.     End If
  243. 'Status not ready, solved or user wanted new game
  244.     InitField
  245. End Sub
  246. Sub MenuSettings_Click ()
  247. 'Tell player to wait
  248.     MousePointer = HOURGLASS
  249. 'load in the dialog box but don't show
  250.     Load MySet
  251. 'Reflect current number of squares in the X direction
  252.     Select Case NumberXSquares
  253.         Case 8
  254.             MySet.OptionH8.Value = True
  255.         Case 10
  256.             MySet.OptionH10.Value = True
  257.         Case 12
  258.             MySet.OptionH12.Value = True
  259.         Case 14
  260.             MySet.OptionH14.Value = True
  261.         Case 16
  262.             MySet.OptionH16.Value = True
  263.         Case 18
  264.             MySet.OptionH18.Value = True
  265.     End Select
  266. 'Reflect current number of squares in the Y direction
  267.     Select Case NumberYSquares
  268.         Case 6
  269.             MySet.OptionV6.Value = True
  270.         Case 8
  271.             MySet.OptionV8.Value = True
  272.         Case 10
  273.             MySet.OptionV10.Value = True
  274.     End Select
  275. 'Reflect current size of squares
  276.     Select Case SquareSize
  277.         Case 32
  278.             MySet.OptionP32.Value = True
  279.         Case 40
  280.             MySet.OptionP40.Value = True
  281.         Case 48
  282.             MySet.OptionP48.Value = True
  283.     End Select
  284. 'Reflect current timer value
  285.     Select Case SetTimer
  286.         Case 1!
  287.             MySet.OptionS1.Value = True
  288.         Case 2!
  289.             MySet.OptionS2.Value = True
  290.         Case 3!
  291.             MySet.OptionS3.Value = True
  292.         Case 4!
  293.             MySet.OptionS4.Value = True
  294.         Case 5!
  295.             MySet.OptionS5.Value = True
  296.     End Select
  297. 'Reflect current settings file if any
  298.     Select Case SaveFile
  299.         Case SelectSaveFileNo
  300.             MySet.OptionSaveNo.Value = True
  301.             MySet.CheckScore.Enabled = False
  302.         Case SelectSaveFileWIN
  303.             MySet.OptionSaveWIN.Value = True
  304.             MySet.CheckScore.Enabled = True
  305.         Case SelectSaveFileWEP
  306.             MySet.OptionSaveWEP.Value = True
  307.             MySet.CheckScore.Enabled = True
  308.         Case SelectSaveFileMy
  309.             MySet.OptionSaveMy.Value = True
  310.             MySet.CheckScore.Enabled = True
  311.     End Select
  312.     MySet.CheckScore.Value = SaveScore
  313. 'Disable invalid X, Y and Square sizes
  314.     If 18 * SquareSize > ScreenPixelSizeX Then MySet.OptionH18.Enabled = False
  315.     If 16 * SquareSize > ScreenPixelSizeX Then MySet.OptionH16.Enabled = False
  316.     If 14 * SquareSize > ScreenPixelSizeX Then MySet.OptionH14.Enabled = False
  317.     FieldY% = MyMemory.LabelFieldStatus.Height + MyMemory.FieldDesc.Height + (FormHeader / TwipsPerPixel)
  318.     If 10 * SquareSize + FieldY% > ScreenPixelSizeY Then MySet.OptionV10.Enabled = False
  319.     If 8 * SquareSize + FieldY% > ScreenPixelSizeY Then MySet.OptionV8.Enabled = False
  320. 'Tell player we're thru
  321.     MousePointer = DEFAULT
  322. 'now show the form
  323.     MySet.Show MODAL
  324. End Sub
  325. Sub MenuShowRecord_Click ()
  326.     MyGp.Show
  327.     For I% = 0 To 5
  328.         For J% = 0 To 2
  329.             MyGp.PGame.Print Str$((I% * 2) + 8) + " x" + Str$((J% * 2) + 6)
  330.             If ScoreArray(I%, J%) = NoScore Then
  331.                 MyGp.PScore.Print
  332.                 MyGp.PName.Print
  333.             Else
  334.                 MyGp.PScore.Print Str$(ScoreArray(I%, J%))
  335.                 MyGp.PName.Print " " + ScoreArrayName(I%, J%)
  336.             End If
  337.         Next J%
  338.     Next I%
  339. End Sub
  340. Sub MyTimer (Timerval As Single)
  341. 'wait seconds asked for by caller
  342.     Start! = Timer
  343.     Finish! = Start! + Timerval
  344.     Do While current! < Finish!
  345.         current! = Timer
  346.     Loop
  347. End Sub
  348. Sub ShowSquare (X As Integer, Y As Integer, Scene As Integer)
  349. 'clear the square first
  350.     Line (X, Y)-(X + SquareSize - 1, Y + SquareSize - 1), GRAY_LIGHT, B
  351.     Line (X + 1, Y + 1)-(X + SquareSize - 2, Y + SquareSize - 2), GRAY_LIGHT, B
  352. 'set offset to center
  353.     Xc% = X + (SquareSize / 2)
  354.     Yc% = Y + (SquareSize / 2)
  355. 'set size of object, size% is offset from center
  356.     Size% = SquareSize / 4
  357. 'Select Color
  358.     Select Case Scene
  359.         
  360.         Case 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88
  361.             Color& = BLACK
  362.             Color2& = WHITE
  363.         
  364.         Case 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89
  365.             Color& = RED
  366.             Color2& = YELLOW
  367.         
  368.         Case 2, 10, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90
  369.             Color& = GREEN
  370.             Color2& = BLUE
  371.         
  372.         Case 3, 11, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91
  373.             Color& = BLUE
  374.             Color2& = GREEN
  375.         
  376.         Case 4, 12, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92
  377.             Color& = YELLOW
  378.             Color2& = RED
  379.         
  380.         Case 5, 13, 21, 29, 37, 45, 53, 61, 69, 77, 85, 93
  381.             Color& = MAGENTA
  382.             Color2& = CYAN
  383.         
  384.         Case 6, 14, 22, 30, 38, 46, 54, 62, 70, 78, 86, 94
  385.             Color& = CYAN
  386.             Color2& = MAGENTA
  387.         
  388.         Case 7, 15, 23, 31, 39, 47, 55, 63, 71, 79, 87, 95
  389.             Color& = WHITE
  390.             Color2& = BLACK
  391.     End Select
  392. 'now show scene
  393.     Select Case Scene
  394.         
  395.         Case 0 To 7
  396.             'draw square, no fill color
  397.             Line (Xc% - Size%, Yc% - Size%)-(Xc% + Size%, Yc% + Size%), Color&, B
  398.         
  399.         Case 8 To 15
  400.             'draw square, filled
  401.             Line (Xc% - Size%, Yc% - Size%)-(Xc% + Size%, Yc% + Size%), Color&, BF
  402.         
  403.         Case 16 To 23
  404.             'draw circle, no fill color
  405.             Circle (Xc%, Yc%), Size%, Color&
  406.         
  407.         Case 24 To 31
  408.             'draw circle, filled
  409.             FillColor = Color&
  410.             FillStyle = SOLID
  411.             Circle (Xc%, Yc%), Size%, Color&
  412.             FillStyle = TRANSPARENT
  413.         
  414.         Case 32 To 39
  415.             'draw triangle, no fill color
  416.             Line (Xc%, Yc% - Size%)-(Xc% + Size%, Yc% + Size%), Color&
  417.             Line -(Xc% - Size%, Yc% + Size%), Color&
  418.             Line -(Xc%, Yc% - Size%), Color&
  419.         
  420.         Case 40 To 47
  421.             'draw triangle, filled
  422.             Line (Xc%, Yc% - Size%)-(Xc% + Size%, Yc% + Size%), Color&
  423.             Line -(Xc% - Size%, Yc% + Size%), Color&
  424.             Line -(Xc%, Yc% - Size%), Color&
  425.             FillColor = Color&
  426.             FillStyle = SOLID
  427.             FloodFill hDC, Xc%, Yc%, Color&
  428.             FillStyle = TRANSPARENT
  429.         
  430.         Case 48 To 55
  431.             'draw upside down triangle, no fill color
  432.             Line (Xc%, Yc% + Size%)-(Xc% + Size%, Yc% - Size%), Color&
  433.             Line -(Xc% - Size%, Yc% - Size%), Color&
  434.             Line -(Xc%, Yc% + Size%), Color&
  435.         
  436.         Case 56 To 63
  437.             'draw upside down triangle, filled
  438.             Line (Xc%, Yc% + Size%)-(Xc% + Size%, Yc% - Size%), Color&
  439.             Line -(Xc% - Size%, Yc% - Size%), Color&
  440.             Line -(Xc%, Yc% + Size%), Color&
  441.             FillColor = Color&
  442.             FillStyle = SOLID
  443.             FloodFill hDC, Xc%, Yc%, Color&
  444.             FillStyle = TRANSPARENT
  445.         
  446.         Case 64 To 71
  447.             'draw diamond, no fill color
  448.             Line (Xc%, Yc% - Size%)-(Xc% + Size%, Yc%), Color&
  449.             Line -(Xc%, Yc% + Size%), Color&
  450.             Line -(Xc% - Size%, Yc%), Color&
  451.             Line -(Xc%, Yc% - Size%), Color&
  452.         
  453.         Case 72 To 79
  454.             'draw diamond, filled
  455.             Line (Xc%, Yc% - Size%)-(Xc% + Size%, Yc%), Color&
  456.             Line -(Xc%, Yc% + Size%), Color&
  457.             Line -(Xc% - Size%, Yc%), Color&
  458.             Line -(Xc%, Yc% - Size%), Color&
  459.             FillColor = Color&
  460.             FillStyle = SOLID
  461.             FloodFill hDC, Xc%, Yc%, Color&
  462.             FillStyle = TRANSPARENT
  463.         
  464.         Case 80 To 87
  465.             'draw double square, filled
  466.             Line (Xc% - Size%, Yc% - Size%)-(Xc% + Size%, Yc% + Size%), Color&, BF
  467.             Line (Xc% - Size% / 2, Yc% - Size% / 2)-(Xc% + Size% / 2, Yc% + Size% / 2), Color2&, BF
  468.         
  469.         Case 88 To 95
  470.             'draw double circle, filled
  471.             FillColor = Color&
  472.             FillStyle = SOLID
  473.             Circle (Xc%, Yc%), Size%, Color&
  474.             FillColor = Color2&
  475.             Circle (Xc%, Yc%), Size% / 2, Color2&
  476.             FillStyle = TRANSPARENT
  477.         Case Else
  478.             'In case I missed one
  479.             CurrentX = Xc%
  480.             CurrentY = Yc%
  481.             Print Str$(Scene)
  482.     End Select
  483. End Sub
  484.